/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package rpt.lib.relatorio;

import java.awt.Color;
import java.sql.Connection;
import java.util.ArrayList;
import java.util.Map;
import net.sf.jasperreports.engine.design.JasperDesign;
import java.util.logging.Level;
import java.util.logging.Logger;
import net.sf.jasperreports.engine.JRBand;
import net.sf.jasperreports.engine.JRDataSource;
import net.sf.jasperreports.engine.JRException;
import net.sf.jasperreports.engine.JRSection;
import net.sf.jasperreports.engine.JRVariable;
import net.sf.jasperreports.engine.JasperCompileManager;
import net.sf.jasperreports.engine.JasperFillManager;
import net.sf.jasperreports.engine.JasperPrint;
import net.sf.jasperreports.engine.JasperReport;
import net.sf.jasperreports.engine.design.JRDesignExpression;
import net.sf.jasperreports.engine.design.JRDesignField;
import net.sf.jasperreports.engine.design.JRDesignGroup;
import net.sf.jasperreports.engine.design.JRDesignLine;
import net.sf.jasperreports.engine.design.JRDesignParameter;
import net.sf.jasperreports.engine.design.JRDesignQuery;
import net.sf.jasperreports.engine.design.JRDesignRectangle;
import net.sf.jasperreports.engine.design.JRDesignSection;
import net.sf.jasperreports.engine.design.JRDesignStaticText;
import net.sf.jasperreports.engine.design.JRDesignTextField;
import net.sf.jasperreports.engine.design.JRDesignVariable;
import net.sf.jasperreports.engine.type.CalculationEnum;
import net.sf.jasperreports.engine.type.HorizontalAlignEnum;
import net.sf.jasperreports.engine.type.PositionTypeEnum;
import net.sf.jasperreports.engine.type.ResetTypeEnum;
import net.sf.jasperreports.engine.type.SplitTypeEnum;
import net.sf.jasperreports.engine.type.VerticalAlignEnum;
import net.sf.jasperreports.view.JasperViewer;

/**
 *
 * @author Roberto
 */
public class CRelatorioJasperDesign extends JasperDesign {

    /**************************************************************************/
    /***                                                                    ***/
    /**************************************************************************/
    public CRelatorioJasperDesign() {
        super();
        setName(toString());
        setPageWidth(595);
        setPageHeight(842);
        setColumnWidth(500);
        //    setColumnSpacing(0);
        setLeftMargin(71);
        setRightMargin(24);
        setTopMargin(30);
        setBottomMargin(20);
    }

    public static enum enumTipoBanda {
        nenhum, titulo, cabecalhoPagina, cabecalhoGrupo, cabecalhoColuna,
        detalhe, rodapePagina, rodapeGrupo, rodapeColuna, sumario
    };

    protected ArrayList<CSubRelatorioBasico> fListaSubRelatorio = 
            new ArrayList<CSubRelatorioBasico>();
    
    //
    public void adicionarSubRelatorio(
            final CSubRelatorioBasico aSubRelatorio) {
                //
        //JRDesignParameter param = new JRDesignParameter(); 
        fListaSubRelatorio.add(aSubRelatorio);
    }
    //
    public void compilarSubRelatorios() {
        //
        for (CSubRelatorioBasico sr : fListaSubRelatorio) {
            try {
                JasperCompileManager.compileReport(sr.getRelatorio());
            } catch (JRException ex) {
                Logger.getLogger(CRelatorioBasico.class.getName()).log(Level.SEVERE, null, ex);
            }
        }
    }
    //
    public void compilarRelatorio(final JasperReport aJasperReport) {
        try {
            //
            JasperReport jasperReport = JasperCompileManager.compileReport(this);
            compilarSubRelatorios();
        } catch (JRException ex) {
            Logger.getLogger(CRelatorioBasico.class.getName()).log(Level.SEVERE, null, ex);
        }
        //
    }
    
    /**************************************************************************/
    /***                                                                    ***/
    /**************************************************************************/
    public JasperPrint getImpressor(
            final CRelatorioBasico aRelatorio,
            final CSubRelatorioBasico aSubRelatorio,
            final Integer aIndiceSubRelatorio,
            final Map aMapaParametros,
            final Object aOrigemDados) {
        JasperPrint jasperPrint = null;
        try {
            //aRelatorioBasico.preparar();
            CRelatorioJasperDesign r = null;
            JasperReport vJasperReport = null;
            Map m = null;
            if (aSubRelatorio == null) {
                vJasperReport = JasperCompileManager.compileReport(aRelatorio);
                m = aMapaParametros;
            }
            else {
                String s = "sub_"+aIndiceSubRelatorio;
                aSubRelatorio.getRelatorio().setName(s);
                JRDesignParameter p = parametro(
                        s,vJasperReport,JasperReport.class);
                JRDesignExpression e1 = new JRDesignExpression(); // expressao("$P{"+s+"}",JasperReport.class);
                //p.setDefaultValueExpression(e1);
                //JRDesignExpression e2 = expressao("$P{"+s+"}",JasperReport.class);
                e1.setValueClass(JasperReport.class);
                e1.addParameterChunk(s);
                //aSubRelatorio.setExpression(e1);
                //aSubRelatorio.setPositionType(JRDesignElement.POSITION_TYPE_FLOAT); 
                aMapaParametros.put(s,vJasperReport);
                vJasperReport = JasperCompileManager.compileReport(aSubRelatorio.getRelatorio());
                /*
                JRDesignParameter parameter = new JRDesignParameter();
                parameter.setName(s);
                parameter.setDefaultValueExpression(expressao(aValor, String.class));
                parameter.setValueClass(aClasse);
                try {
                addParameter(parameter);
                } catch (JRException ex) {
                Logger.getLogger(CRelatorioJasperAncestral.class.getName()).log(Level.SEVERE, null, ex);
                }
                return parameter;
                 *  
                 * 
                 */
                
            }
            //
            if (aOrigemDados instanceof Connection) {
                jasperPrint = JasperFillManager.fillReport(vJasperReport, m, (Connection) aOrigemDados);
            } else if (aOrigemDados instanceof JRDataSource) {
                jasperPrint = JasperFillManager.fillReport(vJasperReport, m, (JRDataSource) aOrigemDados);
            }
            //
        } catch (Exception ex) {
            Logger.getLogger(CRelatorioBasico.class.getName()).log(Level.SEVERE, null, ex);
        }
        return jasperPrint;
    }    

    /**************************************************************************/
    /***                                                                    ***/
    /**************************************************************************/
    private JasperPrint prepararImpressor(
            final CRelatorioBasico aRelatorioBasico,
            final Map aMapaParametros,
            final Object aOrigemDados) {
        int vContador = 0;
        for (CSubRelatorioBasico sb : fListaSubRelatorio) {
            JasperPrint jasperPrintSub = getImpressor(aRelatorioBasico,sb,vContador,aMapaParametros,aOrigemDados);
            vContador++;
        }
        JasperPrint jasperPrint = getImpressor(aRelatorioBasico,null,null,aMapaParametros,aOrigemDados);
        return jasperPrint;
    }


    /**
     * Sets the detail band.
     * @deprecated Replaced by {@link #getDetailSection()}.
     */
    public void setDetail(JRBand detail) {
        
        JRSection vDs = getDetailSection();
       
        JRBand[] bands = vDs.getBands(); 
        if (bands == null || bands.length == 0)
        {
            ((JRDesignSection)vDs).addBand(detail);
        }
        else
        {
            ((JRDesignSection)vDs).removeBand(0);
            ((JRDesignSection)vDs).addBand(0, detail);
        }
    }
    /**************************************************************************/
    /***                                                                    ***/
    /**************************************************************************/
    public void runReport(
            final CRelatorioBasico aRelatorioBasico,
            final Map aMapaParametros,
            final Object aOrigemDados) throws JRException {
        //
        //Map params = new HashMap(); 
        //params.put("sub",sub); 
        //
        JasperPrint jasperPrint = prepararImpressor(aRelatorioBasico,aMapaParametros,aOrigemDados);
        try {
            if (jasperPrint != null) {
                JasperViewer.viewReport(jasperPrint, false);
            }
        } catch (Exception ex) {
            String connectMsg = "Não foi possível criar o relatório: "
                    + ex.getMessage() + " " + ex.getLocalizedMessage();
            System.out.println(connectMsg);
        }
    }

    /**************************************************************************/
    /***                                                                    ***/
    /**************************************************************************/
    public CEstiloRelatorio estilo(
            final String aNome,
            final String aNomeFonte, final int aTamanhoFonte, final boolean aBold,
            final HorizontalAlignEnum aHorizontalAlignEnum,
            final VerticalAlignEnum aVerticalAlignEnum,
            final Color aCorFrente, final Color aCorFundo,
            final String aNomeFontePdf, final String aPdfEncoding, final boolean aPdfEmbedded,
            final boolean aBrancoSendoNulo) {
        //
        CEstiloRelatorio ds = new CEstiloRelatorio();
        ds.setName(aNome);
        ds.setBold(aBold);
        ds.setDefault(true);
        ds.setForecolor(aCorFrente);
        ds.setBackcolor(aCorFundo);
        ds.setFontName(aNomeFonte);
        ds.setFontSize(aTamanhoFonte);
        ds.setHorizontalAlignment(aHorizontalAlignEnum);
        ds.setVerticalAlignment(aVerticalAlignEnum);
        ds.setPdfFontName(aNomeFontePdf);
        ds.setPdfEncoding(aPdfEncoding);
        ds.setPdfEmbedded(aPdfEmbedded);
        try {
            addStyle(ds);
        } catch (JRException ex) {
            Logger.getLogger(CRelatorioJasperAncestral.class.getName()).log(Level.SEVERE, null, ex);
        }
        ds.setBlankWhenNull(aBrancoSendoNulo);
        return ds;
    }

    ;

    /**************************************************************************/
    /***                                                                    ***/
    /**************************************************************************/

    public CEstiloRelatorio estilo(
            String aNome,
            String aNomeFonte, int aTamanhoFonte, boolean aBold,
            Color aCorFrente, Color aCorFundo,
            String aNomeFontePdf, String aPdfEncoding, boolean aPdfEmbedded,
            boolean aBrancoSendoNulo) {
        //
        return estilo(aNome, aNomeFonte, aTamanhoFonte, aBold,
                HorizontalAlignEnum.LEFT,
                VerticalAlignEnum.TOP,
                aCorFrente, aCorFundo, aNomeFontePdf, aPdfEncoding, aPdfEmbedded, aBrancoSendoNulo);
    }

    ;

    /**************************************************************************/
    /***                                                                    ***/
    /**************************************************************************/
/*
    public JRDesignStyle estiloBold() {
        JRDesignStyle boldStyle = new JRDesignStyle();
        boldStyle.setName("Arial_Bold");
        boldStyle.setFontName("Arial");
        boldStyle.setFontSize(12);
        boldStyle.setBold(true);
        boldStyle.setPdfFontName("Helvetica-Bold");
        boldStyle.setPdfEncoding("Cp1252");
        boldStyle.setPdfEmbedded(false);
        try {
            addStyle(boldStyle);
        } catch (JRException ex) {
            Logger.getLogger(CRelatorioJasperAncestral.class.getName()).log(Level.SEVERE, null, ex);
        }
        return boldStyle;
    }
*/
    /**************************************************************************/
    /***                                                                    ***/
    /**************************************************************************/

    public JRDesignParameter parametro(
            String aNomeParametro,
            Object aValor,
            Class aClasse) {
        //
        JRDesignParameter parameter = new JRDesignParameter();
        parameter.setName(aNomeParametro);
        //parameter.setDefaultValueExpression(expressao(aValor, aClasse));
        parameter.setValueClass(aClasse);
        try {
            addParameter(parameter);
        } catch (JRException ex) {
            Logger.getLogger(CRelatorioJasperAncestral.class.getName()).log(Level.SEVERE, null, ex);
        }
        return parameter;
    }

    /**************************************************************************/
    /***                                                                    ***/
    /**************************************************************************/
    public JRDesignQuery query(String aQueryStr) {
        JRDesignQuery query = new JRDesignQuery();
        query.setText(aQueryStr);
        setQuery(query);
        return query;
    }

    /**************************************************************************/
    /***                                                                    ***/
    /**************************************************************************/
    public CBandaRelatorio banda(enumTipoBanda aTipoBanda, int aAlturaPx, CEstiloRelatorio aEstilo) {
        CBandaRelatorio jrdb = new CBandaRelatorio(this, aEstilo);
        jrdb.setSplitType(SplitTypeEnum.STRETCH);
        jrdb.setHeight(aAlturaPx);
        switch (aTipoBanda) {
            case nenhum: {
                break;
            }
            case titulo: {
                setTitle(jrdb);
                break;
            }
            case cabecalhoPagina: {
                setPageHeader(jrdb);
                break;
            }
            case cabecalhoColuna: {
                setColumnHeader(jrdb);
                break;
            }
            case detalhe: {
                setDetail(jrdb);
                break;
            }
            case rodapeColuna: {
                setColumnFooter(jrdb);
                break;
            }
            case rodapePagina: {
                setPageFooter(jrdb);
                break;
            }
            case sumario: {
                setSummary(jrdb);
                break;
            }
        }
        return jrdb;
    }

    /**************************************************************************/
    /***                                                                    ***/
    /**************************************************************************/
    public JRDesignLine traco(
            int aX, int aY, int aW, int aH, Color aCorFundo, PositionTypeEnum aTipoPosicao) {
        JRDesignLine line = new JRDesignLine();
        line.setX(aX);
        line.setY(aY);
        line.setWidth(aW);
        line.setHeight(aH);
        line.setForecolor(aCorFundo);
        line.setPositionType(aTipoPosicao);
        return line;
    }

    /**************************************************************************/
    /***                                                                    ***/
    /**************************************************************************/
    public JRDesignField campo(String aNomeCampo, Class aClasse) {
        JRDesignField df = new JRDesignField();
        df.setName(aNomeCampo);
        df.setValueClass(aClasse);
        try {
            addField(df);
        } catch (JRException ex) {
            Logger.getLogger(this.getName()).log(Level.SEVERE, null, ex);
        }
        return df;
    }

    /**************************************************************************/
    /***                                                                    ***/
    /**************************************************************************/
    public JRDesignTextField campoTexto(
            String aExpressao,
            Class aClasse,
            String aPadrao,
            int aX, int aY, int aW, int aH,
            byte aModo,
            CEstiloRelatorio aEstilo,
            CBandaRelatorio aBanda) {
        //
        return aBanda.campoTexto(aExpressao, aClasse, aPadrao, aX, aY, aW, aH, aEstilo);
    }

    /**************************************************************************/
    /***                                                                    ***/
    /**************************************************************************/
    public JRDesignStaticText textoEstatico(
            String aTexto,
            int aX, int aY, int aW, int aH,
            byte aModo,
            byte aAlinhamentoHorizontal,
            CEstiloRelatorio aEstilo,
            CBandaRelatorio aBanda) {
        //
        return aBanda.textoEstatico(aTexto, aX, aY, aW, aH, aEstilo);
    }

    /**************************************************************************/
    /***                                                                    ***/
    /**************************************************************************/
    public JRDesignExpression expressao(Object aTexto, Class aClasse) {
        JRDesignExpression expression = new JRDesignExpression();
        expression.setValueClass(aClasse);
        expression.setText(aTexto.toString());
        return expression;
    }

    /**************************************************************************/
    /***                                                                    ***/
    /**************************************************************************/
    public JRDesignVariable variavel(String aNome, Class aClasse) {
        JRDesignVariable v = new JRDesignVariable();
        v.setName(aNome);
        v.setValueClass(aClasse);
        v.setResetType(ResetTypeEnum.GROUP);
        v.setCalculation(CalculationEnum.SYSTEM);
        try {
            addVariable(v);
        } catch (JRException ex) {
            Logger.getLogger(CRelatorioJasperDesign.class.getName()).log(Level.SEVERE, null, ex);
        }
        return v;
    }

    /**************************************************************************/
    /***                                                                    ***/
    /**************************************************************************/
    /*
    public JRDesignGroup grupoVariavel(
    JRDesignVariable aVariavel, String aNome, Class aClasse) {
    //
    JRDesignGroup g = new JRDesignGroup();
    g.setName(aNome);
    aVariavel.setResetGroup(g);
    return g;
    }
     */
    /**************************************************************************/
    /***                                                                    ***/
    /**************************************************************************/
    public JRDesignExpression expressaoVariavel(
            JRDesignVariable aVariavel, String aNome, Class aClasse, String aExpressao) {
        //
        JRDesignExpression e = expressao(aExpressao, java.lang.Integer.class);
        e.setValueClass(aClasse);
        e.setText(aExpressao);
        aVariavel.setInitialValueExpression(e);
        return e;
    }

    /**************************************************************************/
    /***                                                                    ***/
    /**************************************************************************/
    public JRDesignRectangle retangulo(
            int aX, int aY, int aW, int aH,
            CBandaRelatorio aBanda) {
        //
        return aBanda.retangulo(aX, aY, aW, aH);
    }

    /**************************************************************************/
    /***                                                                    ***/
    /**************************************************************************/
    public JRDesignGroup Grupo(
            int aX, int aY, int aW, int aH,
            CBandaRelatorio aBanda) {
        //
        JRDesignGroup g = new JRDesignGroup();
        JRSection s = g.getGroupHeaderSection();
        JRBand[] b = s.getBands();
        //
        return new JRDesignGroup();
    }
    /**************************************************************************/
    /***                                                                    ***/
    /**************************************************************************/
    /*
    
    JRDesignStyle italicStyle = new JRDesignStyle();
    italicStyle.setName("Arial_Italic");
    italicStyle.setFontName("Arial");
    italicStyle.setFontSize(12);
    italicStyle.setItalic(true);
    italicStyle.setPdfFontName("Helvetica-Oblique");
    italicStyle.setPdfEncoding("Cp1252");
    italicStyle.setPdfEmbedded(false);
    jasperDesign.addStyle(italicStyle
    
    //Parameters
    
    JRDesignParameter parameter = new JRDesignParameter();
    parameter.setName("ReportTitle");
    parameter.setValueClass(java.lang.String.class);
    jasperDesign.addParameter(parameter);
    
    parameter = new JRDesignParameter();
    parameter.setName("OrderByClause");
    parameter.setValueClass(java.lang.String.class);
    jasperDesign.addParameter(parameter);
    
    //Query
    JRDesignQuery query = new JRDesignQuery();
    query.setText("SELECT * FROM Address $P!{OrderByClause}");
    jasperDesign.setQuery(query);
    
    //Fields
    JRDesignField field = new JRDesignField();
    field.setName("Id");
    field.setValueClass(java.lang.Integer.class);
    jasperDesign.addField(field);
    
    field = new JRDesignField();
    field.setName("FirstName");
    field.setValueClass(java.lang.String.class);
    jasperDesign.addField(field);
    
    field = new JRDesignField();
    field.setName("LastName");
    field.setValueClass(java.lang.String.class);
    jasperDesign.addField(field);
    
    field = new JRDesignField();
    field.setName("Street");
    field.setValueClass(java.lang.String.class);
    jasperDesign.addField(field);
    
    field = new JRDesignField();
    field.setName("City");
    field.setValueClass(java.lang.String.class);
    jasperDesign.addField(field);
    
    //Variables
    JRDesignVariable variable = new JRDesignVariable();
    variable.setName("CityNumber");
    variable.setValueClass(java.lang.Integer.class);
    variable.setResetType(JRVariable.RESET_TYPE_GROUP);
    JRDesignGroup group = new JRDesignGroup();
    group.setName("CityGroup");
    variable.setResetGroup(group);
    variable.setCalculation(JRVariable.CALCULATION_SYSTEM);
    JRDesignExpression expression = new JRDesignExpression();
    expression.setValueClass(java.lang.Integer.class);
    expression.setText("($V{CityNumber} != null)?(new Integer($V{CityNumber}.intValue() + 1)):(new Integer(1))");
    variable.setInitialValueExpression(expression);
    jasperDesign.addVariable(variable);
    
    variable = new JRDesignVariable();
    variable.setName("AllCities");
    variable.setValueClass(java.lang.String.class);
    variable.setResetType(JRVariable.RESET_TYPE_REPORT);
    variable.setCalculation(JRVariable.CALCULATION_SYSTEM);
    jasperDesign.addVariable(variable);
    
    //Groups
    group.setMinHeightToStartNewPage(60);
    expression = new JRDesignExpression();
    expression.setValueClass(java.lang.String.class);
    expression.setText("$F{City}");
    group.setExpression(expression);
    
    JRDesignBand band = new JRDesignBand();
    band.setHeight(20);
    JRDesignRectangle rectangle = new JRDesignRectangle();
    rectangle.setX(0);
    rectangle.setY(4);
    rectangle.setWidth(515);
    rectangle.setHeight(15);
    rectangle.setForecolor(new Color(0xC0, 0xC0, 0xC0));
    rectangle.setBackcolor(new Color(0xC0, 0xC0, 0xC0));
    band.addElement(rectangle);
    JRDesignTextField textField = new JRDesignTextField();
    textField.setX(0);
    textField.setY(4);
    textField.setWidth(515);
    textField.setHeight(15);
    textField.setBackcolor(new Color(0xC0, 0xC0, 0xC0));
    textField.setMode(JRElement.MODE_OPAQUE);
    textField.setHorizontalAlignment(JRAlignment.HORIZONTAL_ALIGN_LEFT);
    textField.setStyle(boldStyle);
    expression = new JRDesignExpression();
    expression.setValueClass(java.lang.String.class);
    expression.setText("\"  \" + String.valueOf($V{CityNumber}) + \". \" + String.valueOf($F{City})");
    textField.setExpression(expression);
    band.addElement(textField);
    JRDesignLine line = new JRDesignLine();
    line.setX(0);
    line.setY(19);
    line.setWidth(515);
    line.setHeight(0);
    band.addElement(line);
    group.setGroupHeader(band);
    
    band = new JRDesignBand();
    band.setHeight(20);
    line = new JRDesignLine();
    line.setX(0);
    line.setY(-1);
    line.setWidth(515);
    line.setHeight(0);
    band.addElement(line);
    JRDesignStaticText staticText = new JRDesignStaticText();
    staticText.setX(400);
    staticText.setY(0);
    staticText.setWidth(60);
    staticText.setHeight(15);
    staticText.setHorizontalAlignment(JRAlignment.HORIZONTAL_ALIGN_RIGHT);
    staticText.setStyle(boldStyle);
    staticText.setText("Count : ");
    band.addElement(staticText);
    textField = new JRDesignTextField();
    textField.setX(460);
    textField.setY(0);
    textField.setWidth(30);
    textField.setHeight(15);
    textField.setHorizontalAlignment(JRAlignment.HORIZONTAL_ALIGN_RIGHT);
    textField.setStyle(boldStyle);
    expression = new JRDesignExpression();
    expression.setValueClass(java.lang.Integer.class);
    expression.setText("$V{CityGroup_COUNT}");
    textField.setExpression(expression);
    band.addElement(textField);
    group.setGroupFooter(band);
    
    jasperDesign.addGroup(group);
    
    //Title
    band = new JRDesignBand();
    band.setHeight(50);
    line = new JRDesignLine();
    line.setX(0);
    line.setY(0);
    line.setWidth(515);
    line.setHeight(0);
    band.addElement(line);
    textField = new JRDesignTextField();
    textField.setBlankWhenNull(true);
    textField.setX(0);
    textField.setY(10);
    textField.setWidth(515);
    textField.setHeight(30);
    textField.setHorizontalAlignment(JRAlignment.HORIZONTAL_ALIGN_CENTER);
    textField.setStyle(normalStyle);
    textField.setFontSize(22);
    expression = new JRDesignExpression();
    expression.setValueClass(java.lang.String.class);
    expression.setText("$P{ReportTitle}");
    textField.setExpression(expression);
    band.addElement(textField);
    jasperDesign.setTitle(band);
    
    //Page header
    band = new JRDesignBand();
    band.setHeight(20);
    rectangle = new JRDesignRectangle();
    rectangle.setX(0);
    rectangle.setY(5);
    rectangle.setWidth(515);
    rectangle.setHeight(15);
    rectangle.setForecolor(new Color(0x33, 0x33, 0x33));
    rectangle.setBackcolor(new Color(0x33, 0x33, 0x33));
    band.addElement(rectangle);
    staticText = new JRDesignStaticText();
    staticText.setX(0);
    staticText.setY(5);
    staticText.setWidth(55);
    staticText.setHeight(15);
    staticText.setForecolor(Color.white);
    staticText.setBackcolor(new Color(0x33, 0x33, 0x33));
    staticText.setMode(JRElement.MODE_OPAQUE);
    staticText.setHorizontalAlignment(JRAlignment.HORIZONTAL_ALIGN_CENTER);
    staticText.setStyle(boldStyle);
    staticText.setText("ID");
    band.addElement(staticText);
    staticText = new JRDesignStaticText();
    staticText.setX(55);
    staticText.setY(5);
    staticText.setWidth(205);
    staticText.setHeight(15);
    staticText.setForecolor(Color.white);
    staticText.setBackcolor(new Color(0x33, 0x33, 0x33));
    staticText.setMode(JRElement.MODE_OPAQUE);
    staticText.setStyle(boldStyle);
    staticText.setText("Name");
    band.addElement(staticText);
    staticText = new JRDesignStaticText();
    staticText.setX(260);
    staticText.setY(5);
    staticText.setWidth(255);
    staticText.setHeight(15);
    staticText.setForecolor(Color.white);
    staticText.setBackcolor(new Color(0x33, 0x33, 0x33));
    staticText.setMode(JRElement.MODE_OPAQUE);
    staticText.setStyle(boldStyle);
    staticText.setText("Street");
    band.addElement(staticText);
    jasperDesign.setPageHeader(band);
    
    //Column header
    band = new JRDesignBand();
    jasperDesign.setColumnHeader(band);
    
    //Detail
    band = new JRDesignBand();
    band.setHeight(20);
    textField = new JRDesignTextField();
    textField.setX(0);
    textField.setY(4);
    textField.setWidth(50);
    textField.setHeight(15);
    textField.setHorizontalAlignment(JRAlignment.HORIZONTAL_ALIGN_RIGHT);
    textField.setStyle(normalStyle);
    expression = new JRDesignExpression();
    expression.setValueClass(java.lang.Integer.class);
    expression.setText("$F{Id}");
    textField.setExpression(expression);
    band.addElement(textField);
    textField = new JRDesignTextField();
    textField.setStretchWithOverflow(true);
    textField.setX(55);
    textField.setY(4);
    textField.setWidth(200);
    textField.setHeight(15);
    textField.setPositionType(JRElement.POSITION_TYPE_FLOAT);
    textField.setStyle(normalStyle);
    expression = new JRDesignExpression();
    expression.setValueClass(java.lang.String.class);
    expression.setText("$F{FirstName} + \" \" + $F{LastName}");
    textField.setExpression(expression);
    band.addElement(textField);
    textField = new JRDesignTextField();
    textField.setStretchWithOverflow(true);
    textField.setX(260);
    textField.setY(4);
    textField.setWidth(255);
    textField.setHeight(15);
    textField.setPositionType(JRElement.POSITION_TYPE_FLOAT);
    textField.setStyle(normalStyle);
    expression = new JRDesignExpression();
    expression.setValueClass(java.lang.String.class);
    expression.setText("$F{Street}");
    textField.setExpression(expression);
    band.addElement(textField);
    line = new JRDesignLine();
    line.setX(0);
    line.setY(19);
    line.setWidth(515);
    line.setHeight(0);
    line.setForecolor(new Color(0x80, 0x80, 0x80));
    line.setPositionType(JRElement.POSITION_TYPE_FLOAT);
    band.addElement(line);
    jasperDesign.setDetail(band);
    
    //Column footer
    band = new JRDesignBand();
    jasperDesign.setColumnFooter(band);
    
    //Page footer
    band = new JRDesignBand();
    jasperDesign.setPageFooter(band);
    
    //Summary
    band = new JRDesignBand();
    jasperDesign.setSummary(band)
    
    How to indert charts  into JasperReports
    
    JasperReports now has built-in support for charts. There is a new chart component ready to use like we already had images, text fields, subreports and other elements.
    
    This greatly simplifies the way charts are included inside reports, because previously the user had to completely rely on scriptlets in order to gather the chart data and render the chart using an image element in the report template.
    
    Now with the new chart component, the user only has to make the desired visual settings to it and define the expressions that will help the engine built-up the chart dataset in a incremental fashion during the iteration through the report data source.
    
    When including and configuring a chart component, there are three entities involved:
    - the overall chart component;
    - the chart dataset (groups chart data related settings);
    - the chart plot (groups visual settings related to the way the chart items are rendered);
    
    JasperReports currently supports the following types of charts:
    Pie, Pie 3D, Bar, Bar 3D, XY Bar, Stacked Bar, Stacked Bar 3D, Line, XY Line, Area, XY Area, Scatter Plot, Bubble, Time series, High Low Open Close, Candlestick.
    
    These types of charts use several types of datasets (each type of chart works with certain types of datasets): Pie Dataset, Category Dataset, XY Dataset, Time Series, Time Period Values, XYZ Dataset, High Low Dataset.
    
    For all charts we can configure the following:
    - border around all sides
    - background color
    - title
    - title position (top, left, bottom, right)
    - title font
    - title color
    - subtitle
    - subtitle color
    - subtitle font
    - show/hide legend
    - plot area background color
    - plot area background transparency (alpha)
    - plot area foreground transparency (alpha)
    - plot orientation (vertical, horizontal)
    - axis labels
    
    For all datasets we can configure:
    - increment type (detail, column, page, group, report)
    - increment group
    - reset type (none, column, page, group, report)
    - reset group
    
    Specific settings by chart type:
    
    Pie 3D
    - depth factor
    
    Bar, XY Bar, Stacked Bar
    - hide/show labels
    - hide/show tick marks
    - hide/show tick labels
    
    Bar 3D, Stacked Bar 3D
    - hide/show labels
    - x offset (3D effect)
    - y offset (3D effect)
    
    Line, XY Line, Scatter Plot, Time series
    - hide/show lines
    - hide/show shapes
    
    Bubble
    - scale type (both axes, domain axis, range axis)
    
    High Low Open Close
    - hide/show close ticks
    - hide/show open ticks
    
    Candlestick
    - hide/show volume
    
    JasperReports uses the JFreeChart library to render the charts and details about how to use this functionality can be found in the supplied "charts" sample
    
     */
}
